public class demo18 {
    public static void main(String[] args) {
        Singleton singleton = Singleton.getInstance();

    }
}

//懒汉模式
class Sington {
    private static volatile Sington instance = null;
    public static Object locker = new Object();

    public static Sington getInstance() {
        //判断是否需要加锁
        if (instance == null) {
            synchronized (locker) {
                //判定是否需要创建实例
                if (instance == null) {
                    instance = new Sington();
                }
            }
        }
        return instance;
    }


}
